package org.gen.code.core.handler;

import org.gen.code.db.dao.DbConfigDao;
import org.gen.code.db.domain.DbConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

@Component
public class CoreHandler {

    @Autowired
    private DbConfigDao dbConfigDao;

    @PostConstruct
    public void init() {
        List<DbConfig> all = dbConfigDao.findAll();
        if (all.size() > 0) {
            System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>已有数据 ：" + all.size() + " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
            return;
        }

        DbConfig dbConfig = new DbConfig();
        dbConfig.setId(1L);
        dbConfig.setDbName("mysql5.7");
        dbConfig.setUrl("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false");
        dbConfig.setDriver("com.mysql.jdbc.Driver");
        dbConfig.setUserName("root");
        dbConfig.setPassword("123456");
        dbConfig.setTableSchema("test1");
        dbConfigDao.save(dbConfig);

        dbConfig.setId(2L);
        dbConfig.setDbName("mysql8.0");
        dbConfig.setUrl("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false");
        dbConfig.setDriver("com.mysql.cj.jdbc.Driver");
        dbConfig.setUserName("root");
        dbConfig.setPassword("123456");
        dbConfig.setTableSchema("test2");
        dbConfigDao.save(dbConfig);

        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>初始化数据完成<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
    }


}
